<?php
class QHolidays
{
	public function __construct($p_strCountry)
	{
		$this->_country	= $p_strCountry;
		$this->_table	= strtolower($p_strCountry).'_holidays';
	}
	public function getAll()
	{
		$strQuery	= '
			SELECT id, date, description, weekday
			FROM '. $this->_table .'
			WHERE 1=1
		';
		$strQuery	.= ' ORDER BY date ASC';
		
		$db 		= Zend_Registry::get('db');
		$resultValue  = $db->fetchAll($strQuery);
		$db->closeConnection();
		
		return $resultValue;
	}
	
	public function get_by_id($p_intId)
	{
		$strQuery	= 'SELECT * FROM '.$this->_table.' WHERE id='.intval($p_intId);
		
		$db 		= Zend_Registry::get('db');
		$arrResult	=  $db->fetchAll($strQuery);
		$db->closeConnection();
		return isset($arrResult[0]) ? $arrResult[0] : null;
	}
	
	public function get_by_date($p_Date)
	{
		$strQuery	= 'SELECT * FROM '.$this->_table.' WHERE date="' . $p_Date . '";' ;
		
		$db 		= Zend_Registry::get('db');
		$arrResult	=  $db->fetchAll($strQuery);
		$db->closeConnection();
		
		return isset($arrResult[0]) ? $arrResult[0] : null;
	}
	
	public function delete($p_intId)
	{
		$strQuery	= 'DELETE FROM '. $this->_table.' WHERE id='.intval($p_intId);
		
		$db 		= Zend_Registry::get('db');
		$arrResult	=  $db->execute($strQuery);
		$db->closeConnection();
		return 1;
	}
	
	public function insert($p_arrParams)
	{
		$db	= Zend_Registry::get('db');
		$resultValue =$db->insert($this->_table,$p_arrParams);
		$db->closeConnection();
		return $resultValue;
	}
	
	public function update($p_arrParams, $p_intId)
	{
		$db	= Zend_Registry::get('db');
		$resultValue = $db->update($this->_table, $p_arrParams, 'id='.intval($p_intId));
		$db->closeConnection();
		return $resultValue;
	}
}
?>